<template>
  <div class="dialog-container">
    <el-form
      ref="form"
      :model="dataForm"
      class="dialog-form"
      :rules="rules"
      label-width="110px"
      size="mini"
      :disabled="dialogType === 'detail'"
    >
      <!-- 自定义表格内容 -->
      <div class="custom-table-panel">
        <component
          :is="flag"
          ref="form2"
          :obj="dataForm"
          :maintena-index="maintenaIndex"
        />
      </div>
    </el-form>
    <!-- <span slot="footer" class="dialog-footer">
      <el-button :loading="saveLoading" class="sure-btn" size="mini" type="primary" @click="handleSave">保存</el-button>
      <el-button size="mini" class="cancel-btn" @click="closeDialog">取消</el-button>
    </span> -->

  </div>
</template>

<script>
// import Jy from './form/jy'
// import Wh from './form/wh'
// import Pjgh from './form/pjgh'
// import Xj from './form/xj'
// import Fyhs from './form/fyhs'
// import Bd from './form/bd'
// import Sjgh from './form/sjgh'
// import Yqxj from './form/yqxj'
// import Yqwh from './form/yqwh'
// import Yqgh from './form/yqgh'
// import Yqjz from './form/yqjz'
// import Yqbd from './form/yqbd'
import FS_BS_BC_JLB from './jsonForm/FS_BS_BC_JLB'
import FS_BZYPGH_JLB from './jsonForm/FS_BZYPGH_JLB'
import FS_CSSZ_JLB from './jsonForm/FS_CSSZ_JLB'
import FS_FYSJ_JLB from './jsonForm/FS_FYSJ_JLB'
import FS_JX_JLB from './jsonForm/FS_JX_JLB'
import FS_JZJG_JLB from './jsonForm/FS_JZJG_JLB'
import FS_SYJG_JLB from './jsonForm/FS_SYJG_JLB'
import FS_XJWH_JLB from './jsonForm/FS_XJWH_JLB'
import FS_YHPGH_JLB from './jsonForm/FS_YHPGH_JLB'
import FS_ZDJCYJY_JL from './jsonForm/FS_ZDJCYJY_JL'
import YQ_BS_BC_JL from './jsonForm/YQ_BS_BC_JL'
import YQ_JYCS_JL from './jsonForm/YQ_JYCS_JL'
import YQ_PYYJZ_JLB from './jsonForm/YQ_PYYJZ_JLB'
import YQ_QTGH_JL from './jsonForm/YQ_QTGH_JL'
import YQ_RCXJ_JLB from './jsonForm/YQ_RCXJ_JLB'
import YQ_WX_JLB from './jsonForm/YQ_WX_JLB'
import YQ_YHPGH_JLB from './jsonForm/YQ_YHPGH_JLB'

import { getById } from '@/api/business/template'
export default {
  name: 'AddTemplatePage',
  components: {
    // Wh, Pjgh, Xj, Yqxj, Yqwh, Yqgh, Yqjz, Yqbd, Jy, Fyhs, Bd, Sjgh,
    FS_BS_BC_JLB,
    FS_BZYPGH_JLB,
    FS_CSSZ_JLB,
    FS_FYSJ_JLB,
    FS_JX_JLB,
    FS_JZJG_JLB,
    FS_SYJG_JLB,
    FS_XJWH_JLB,
    FS_YHPGH_JLB,
    FS_ZDJCYJY_JL,
    YQ_BS_BC_JL,
    YQ_JYCS_JL,
    YQ_PYYJZ_JLB,
    YQ_QTGH_JL,
    YQ_RCXJ_JLB,
    YQ_WX_JLB,
    YQ_YHPGH_JLB
  },
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    dialogType: {
      type: String,
      default: 'detail'
    },
    obj: {
      type: Object,
      default: null
    },
    formDetailsId: {
      type: String,
      default: ''
    },
    maintenaIndex: {
      type: Number,
      default: 0
    },
    outletData: {
      type: Object,
      default: null
    }
  },
  data() {
    return {
      saveLoading: false,
      dataForm: {},
      flag: null,
      rules: {
        name: [{ required: true, message: '请输入名称', trigger: 'blur' }]
      }
    }
  },
  computed: {
    formTempId: function() {
      return this.outletData.formTempId
    }
  },
  watch: {
    formTempId(val) {
      this.initData()
    }
  },
  mounted() {
    this.initData()
  },
  methods: {
    initData() {
      if (this.obj) {
        console.log('page initData')
        if (this.outletData && this.outletData.formTempId) {
          // 查询模板
          getById(this.outletData.formTempId).then(res => {
            if (res.data.obj) {
              this.flag = res.data.obj.modelUrl
            }
            this.dataForm = this.obj
            if (this.$refs.form2) {
              this.$refs.form2.init()
            }
          })
        }
      }
    },
    handleSave() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          const data = this.$refs.form2.getFormData()
          data.maintenaIndex = this.maintenaIndex
          data.id = this.formDetailsId
          this.$emit('saveMaintena', data)
          this.closeDialog()
        }
      })
    },
    closeDialog() {
      this.$emit('closeDialog')
      this.clearData()
      this.$refs['form'].clearValidate()
    },
    clearData() {
      // this.$refs.form2.clearData()
      this.dataForm = {}
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
